package Lib3d.SceneGraph.Impl;


import Lib3d.Vector3d;
import Lib3d.Animation.Animation;
import Lib3d.Animation.AnimationFactory;
import Lib3d.SceneGraph.Node;

import java.util.Collection;

import javax.media.opengl.GLAutoDrawable;

/**
 * An animated group implementation. This is a scene graph group that can be
 * animated.
 * 
 * @author Wassim Chegham
 * @version 0.1
 * @category Lib3d.SceneGraphImpl
 * 
 */
public class AnimatedGroupImpl extends GroupImpl implements Animation {

    private Animation animation;

    public AnimatedGroupImpl() {
        super();
        this.animation = AnimationFactory.createSimpleAnimation();
    }

    public void addAnimation(final Animation animation) {
        final Collection<Node> children = super.children;
        for (final Object element : children) {
            final Node node = (Node) element;
            animation.addChild(node);
        }
        super.children.clear();
        super.addChild(animation);
        this.animation = animation;
    }

    @Override
    public void draw(final GLAutoDrawable gLDrawable) {
        super.draw(gLDrawable);
        this.animation.run();
    }

    public void run() {}

    public void setDistance(final float distance) {
        this.animation.setDistance(distance);
    }

    public void setRotation(final Vector3d rotation, final float angle) {
        this.animation.setRotation(rotation, angle);
    }

    public void setSpeed(final float speed) {
        this.animation.setSpeed(speed);
    }

}
